<template>
  <div class="login-container">
    <el-form :model="ruleForm2" :rules="rules2"
             status-icon
             ref="ruleForm2"
             label-position="left"
             label-width="0px"
             class="demo-ruleForm login-page">
      <h3 class="title" style="font-family: 华文行楷;font-size: 30px;">系统登录</h3>
<!--      用户账号信息-->
      <el-form-item prop="username">
        <el-input type="text"
                  v-model="ruleForm2.username"
                  auto-complete="off"
                 prefix-icon="el-icon-user-solid"
        ></el-input>
        <!--      用户密码信息-->
      </el-form-item>
      <el-form-item prop="password" >
        <el-input type="password"
                  v-model="ruleForm2.password"
                  auto-complete="off"
                  prefix-icon="el-icon-lock"
        ></el-input>
      </el-form-item>
      <el-checkbox
        v-model="checked"
        class="rememberme"
      >记住密码</el-checkbox>
      <el-form-item style="width:100%;">
        <el-button type="primary" style="width:30%;" @click="handleSubmit">登录</el-button>
        <el-button type="primary" style="width:30%;" v-on:click="registerview">注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  import {login} from "@/api/index" //导入api中的info方法
  export default {
    data(){
      return {
        ruleForm2: {
          username: '8',
          password: '123456',
        },
        rules2: {
          username: [{required: true, message: 'please enter your account', trigger: 'blur'}],
          password: [{required: true, message: 'enter your password', trigger: 'blur'}]
        },
        checked: false
      }
    },
    methods: {
      handleSubmit(){
        if(this.ruleForm2.username!=''&&this.ruleForm2.password!='') {
          login({id: this.ruleForm2.username, password: this.ruleForm2.password}).then((res => {
            if (res.data.data.id==this.ruleForm2.username&&res.data.data.password==this.ruleForm2.password) {
              window.localStorage.setItem('id', res.data.data.id)
              window.localStorage.setItem('remark', res.data.data.remark)
              window.localStorage.setItem("token",res.data.data.token)
              window.localStorage.setItem('name', res.data.data.name)
              this.$message({
                type: 'success',
                message: '登录成功'
              })
              this.$router.push({path: '/main/homepage'});
            } else {
              this.$message.error("账号或者密码错误")
            }
          }))
        }else{
          this.$message.error("账号或者密码未填")
        }
          }

      },
      registerview:function ()
      {
        this.$router.push({path:'/register'});
      }


  };
</script>

<style scoped>
  .login-container {
    width: 100%;
    height: 100%;
  }
  .login-page {
    -webkit-border-radius: 5px;
    border-radius: 5px;
    margin: 180px auto;
    width: 350px;
    padding: 35px 35px 15px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
    border-radius: 20px;
  }
  label.el-checkbox.rememberme {
    margin: 0px 0px 15px;
    text-align: left;
  }
</style>
